package com.example.wanandroid

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.example.module_common.arouter.RouterCenter
import kotlinx.android.synthetic.main.activity_main.*
import org.zhx.common.colorful.Builder
import org.zhx.common.colorful.ColorfulText

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        initView()
        // TextView 点击事件
        //textClick()
    }

    private fun textClick() {
        val builder: Builder = Builder(this)
            .targets(getString(R.string.user_agreement)) // 变色的 文字
            .textColor(R.color.colorPrimary)
            .spanClick { _ ->
                val intent = Intent("andoid.intent.action.View");
                intent.action = Intent.ACTION_VIEW;
                intent.data = Uri.parse("http://www.baidu.com");
                startActivity(intent);
            }

        val builder1: Builder = Builder(this)
            .targets(getString(R.string.privacy_policy)) // 变色的 文字
            .textColor(R.color.colorAccent)
            .isUnderline(true)
            .spanClick { _ ->
                val intent = Intent("andoid.intent.action.View");
                intent.action = Intent.ACTION_VIEW;
                intent.data = Uri.parse("http://www.sina.com");
                startActivity(intent);
            }
        //.......所有builder 都可以叠加
        //.......所有builder 都可以叠加
        val textView = findViewById<TextView>(R.id.tv_home)
        val text = ColorfulText()
        text.init(getString(R.string.privacy_content))
        text.onClickListener =
            View.OnClickListener {
                // Toast.makeText(this@MainActivity, "textView", Toast.LENGTH_SHORT).show()
            }
        //...............所有builder 都可以叠加
        //...............所有builder 都可以叠加
        text.creat(builder, builder1)
        text.into(textView)

    }

    private fun initView() {
        progress_view?.setProgress(850f)
        tv_home?.setOnClickListener {
            RouterCenter.toHome()
        }
        tv_knowledge.setOnClickListener {
            RouterCenter.toKnowLedge()
        }
    }
}